import React from 'react';
import { ts2Formatter,renderState,renderEnable } from 'utils';
import moment from 'moment';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "billcode",
        zhname: "单据号",
        type: "FormControl",
        hidepage:{0:true},
        edit: false,
    },
    {
        enname: "organizationId",
        showname: "organizationName",
        codename: "organizationCode",
        zhname: "隶属组织",
        param:{
            "AUTH_refdim": "organization", 
            "AUTH_refcod": "ProfitCheck"
        },
        cascadeName: [{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "marketareaId",
            resetOffersFlag: true,
        }
        ],
        cascadeChildTable:[{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"profitCheckDetails" 
        },{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"profitCheckDetails"
        },{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"profitCheckDetails"
        }],
        type: "RefComponent",
        refname:"organization",
        edit: true,
        required: true,
    },
    {
        enname: "approvalId",
        codename: "approvalCode",
        showname: "approvalName",
        zhname: "审批管理",
        refname: "approvalDocQRSP001",
        type: "RefComponent",
        edit: true,
        required: false,
    },
    {
        enname: "marrkdate",
        zhname: "单据日期",
        edit: true,
        defaultValue:moment(),
        format:"YYYY-MM-DD",
        type: "DatePicker",
    },
    {
        enname: "marketareaId",
        codename: "marketareaCode",
        showname: "marketareaName",
        zhname: "部门片区",
        edit: true,
        alias:"organizationId",
        param:{
            "AUTH_refdim": "marketarea", 
            "AUTH_refcod": "ProfitCheck",
            "EQ_enableState":"0",
        },
        cascadeChildTable:[{
            refKey: "refpk",
            dtoKey: "cpaydeptidId",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refcode",
            dtoKey: "cpaydeptidCode",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refname",
            dtoKey: "cpaydeptidName",
            childType:"profitCheckDetails"
        }],
        type: "RefComponent",
        refname:"departmentRef",
        required: true,
    },
    {
        enname: "marrkId",
        codename: "marrkCode",
        showname: "marrkName",
        zhname: "创建人",
        edit: false,
        hidepage:{0:true},
        param:{
            "AUTH_refdim": "marrk", 
            "AUTH_refcod": "ProfitCheck"
        },
        type: "RefComponent",
        refname: "personRef",
    },
    {
        enname: "commoditybrandId",
        codename: "commoditybrandCode",
        showname: "commoditybrandName",
        zhname: "商品品牌",
        param:{
            "AUTH_refdim": "commoditybrand", 
            "AUTH_refcod": "ProfitCheck"
        },
        cascadeChildTable:[{
            refKey: "refpk",
            dtoKey: "commoditybrandId",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refcode",
            dtoKey: "commoditybrandCode",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refname",
            dtoKey: "commoditybrandName",
            childType:"profitCheckDetails"
        }],
        edit: true,
        type: "RefComponent",
        refname: "brandref",
        required: true,
    },
    {
        enname: "goodscategoryId",
        codename: "goodscategoryCode",
        showname: "goodscategoryName",
        zhname: "商品品类",
        param:{
            "EQ_enableState": "0"
        },
        cascadeChildTable:[{
            refKey: "refpk",
            dtoKey: "goodscategoryId",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refcode",
            dtoKey: "goodscategoryCode",
            childType:"profitCheckDetails"
        },
        {
            refKey: "refname",
            dtoKey: "goodscategoryName",
            childType:"profitCheckDetails"
        }],
        edit: true,
        type: "RefComponent",
        refname: "terminalGoodsCate",
        required: true,
    },
    {
        codename: "state",
        zhname: "审批状态",
        type: "Select",
        hidepage: { 0: true },
        code: "BILL_STATUS",
        required: false,
        edit: false,
    },
    {
        enname:"isEnable",
        zhname:"启用状态",
        required: false,
        options: [{
            "key": 1,
            "value": "已启用"
        }, {
            "key": 2,
            "value": "停用"
        }],
        hidepage:{0:true},
        type: "Radio",
        edit: false
    },
    {
        enname: "profitamount",
        zhname: "补贴金额",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "remark",
        zhname: "摘要",
        edit: true,
        componentClass: "textarea",
        pattern:/^\S*$/,
        message: "不能有空格",
        type: "FormControl",
    },
    {
        enname: "approver",
        zhname: "审批人",
        type: "FormControl",
        required: false,
        hidepage: { 0: true },
        edit: false,
    },
    {
        enname:"approveTime",
        zhname:"审核日期",
        required: false,
        hidepage:{0:true,1:false,2:false},
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: false
    },
    
];

const columnprofitCheckAttachments = [
    {
        title: "标题",
        dataIndex: "filename",
        key: "filename",
        detailwidth: 250,
    }, {
        title: "上传时间",
        dataIndex: "creationTime",
        key: "creationTime",
        detailwidth: 150,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    }, {
        title: "缩略图",
        dataIndex: "fileUrl",
        key: "fileUrl",
        width: 150,
        render: (text, record, index) => {
            if(record.fileUrl.search("jpg") != -1 || record.fileUrl.search("jpeg") != -1 ||record.fileUrl.search("png") != -1){
                return <span>
                <img style={{"width":"35px"}} src={text} />
             </span>
            }else {
                return ""
            }
            
        }
    }, 
    {
        title: "创建人",
        dataIndex: "creator",
        key: "creator",
        width: 150,
    }
]

const columnprofitCheckDetails = [
    {
        title: "补贴项目",
        dataIndex: "profitProjectName",
        key:"profitProjectId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        required:true,
        fixed:"left",
        filedProps: {
            childType: "profitCheckDetails",
            title: "补贴项目",
            refName: "feeType",
            treeNodeDisabledKey:'disabledKey',
            constparam:{
                "EQ_subsidyProjectState": "1",
                "EQ_limitSubsidyProjectState": "1",
                "EQ_isEnable":"1"
            },
            fieldName: "profitProjectName",
            reffields: { refpk: "profitProjectId", refname: "profitProjectName", refcode: "profitProjectCode" }
        },
    },
    {
        title: "归属年月",
        dataIndex: "ownermonth",
        key: "ownermonth",
        width:90,
        renderType: "datepicker",
        required:true,
        validate:false,
        fixed:"left",
        render: (text, record, index) => {
            return new Date(text).getFullYear()+'-'+(new Date(text).getMonth()+1);
        },
        filedProps: {
            format:"YYYY-MM",
        }
    },
    {
        dataIndex: "profitamount",
        key: "profitamount",
        title: "补贴金额",
        width:150,
        renderType: "inputnumber",
        patternMessage:"不为0的数",
        filedProps: {
            precision:2,
        },
        edit: true,
        validate:false,
        required: true,
        fixed:"left",
    },
    {
        title: "门店",
        dataIndex: "shopName",
        key:"shopId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        filedProps: {
            childType: "profitCheckDetails",
            aliasparam: [{
                paramkey: "EQ_organization.id",
                alias: "organizationId",
            }],
            offersparam: {
                currentkey: ["customerName", "customerId", "customerCode","custChanTypeId","custChanTypeName","custChanTypeCode"],
                offerfields: ["customerName", "customerId", "customerCode","custchantypeId","custchantypeName","custchantypeCode"],
            },
            title: "门店",
            refName: "terminal",
            fieldName: "shopName",
            reffields: { refpk: "shopId", refname: "shopName", refcode: "shopCode" }
        },
    },
    {
        title: "客户",
        dataIndex: "customerName",
        key:"customerId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        filedProps: {
            childType: "profitCheckDetails",
            title: "客户",
            refName: "terminalcustomerRef",
            constparam:{
                "AUTH_refdim": "customer", 
                "AUTH_refcod": "ProfitCheck",
                "EQ_isFrozen": "0"
            },
            aliasparam: [{
                paramkey: "EQ_customerAreas.organization.id",
                alias: "organizationId",
            }],
            offersparam: {
                currentkey: ["businessName", "businessId", "businessCode","custChanTypeId","custChanTypeName","custChanTypeCode"],
                offerfields: ["dutyPersonName", "dutyPersonId", "dutyPersonCode","custchantypeId","custchantypeName","custchantypeCode"],
            },
            fieldName: "customerName",
            reffields: { refpk: "customerId", refname: "customerName", refcode: "customerCode" }
        },
    },
    {
        title: "客户渠道",
        dataIndex: "custchantypeName",
        key:"custchantypeId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        filedProps: {
            childType: "profitCheckDetails",
            title: "客户渠道",
            constparam:{
                "AUTH_refdim": "channelType", 
                "AUTH_refcod": "ProfitCheck",
                "EQ_enableState": "1",
            },
            refName: "custchantype",
            fieldName: "custchantypeName",
            reffields: { refpk: "custchantypeId", refname: "custchantypeName", refcode: "custchantypeCode" }
        },
    },
    {
        title: "商品品牌",
        dataIndex: "commoditybrandName",
        key:"commoditybrandId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        required:true,
        filedProps: {
            childType: "profitCheckDetails",
            title: "商品品牌",
            constparam:{
                "AUTH_refdim": "commoditybrand", 
                "AUTH_refcod": "ProfitCheck"
            },
            refName: "brandref",
            fieldName: "commoditybrandName",
            reffields: { refpk: "commoditybrandId", refname: "commoditybrandName", refcode: "commoditybrandCode" }
        },
    },
    {
        title: "商品品类",
        dataIndex: "goodscategoryName",
        key:"goodscategoryId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        required:true,
        filedProps: {
            childType: "profitCheckDetails",
            title: "商品品类",
            constparam:{
                "EQ_enableState": "0"
            },
            refName: "terminalGoodsCate",
            fieldName: "goodscategoryName",
            reffields: { refpk: "goodscategoryId", refname: "goodscategoryName", refcode: "goodscategoryCode" }
        },
    },
    {
        title: "责任业务",
        dataIndex: "dutyPersonName",
        key:"dutyPersonId",
        renderType: "refcomponent",
        width: 150,
        validate: false,
        filedProps: {
            childType: "profitCheckDetails",
            aliasparam: [{
                paramkey: "EQ_personPosts.organization.id",
                alias: "organizationId",
            }],
            title: "责任业务",  
            refName: "terminalPersonRef",
            fieldName: "dutyPersonName",
            reffields: { refpk: "dutyPersonId", refname: "dutyPersonName", refcode: "dutyPersonCode" }
        },
    },
    {
        title: "税率%",
        dataIndex: "taxNum",
        key:"taxNum",
        width: 90,
        renderType:"inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        },
        required:true,
    },
    {
        title: "不含税额",
        dataIndex: "notaxamount",
        key:"notaxamount",
        width: 90,
    },
    {
        title: "税额",
        dataIndex: "taxamount",
        key:"taxamount",
        width: 90,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            min: 0,
        },
        edit: true,
        required: false,
    },
    {
        dataIndex: "activityschemebillcode",
        key: "activityschemebillcode",
        title: "决裁申请单据号",
        render:(text,record) => {
            return <a 
                value="ActivityScheme" 
                name="决裁申请单"
                onClick = {(e)=>{
                    e.preventDefault();//阻止默认事件
                    window.top.handleClick(e,1);//调用打开新页签方法
                    
                }}
                href={encodeURIComponent(encodeURIComponent(`/fmcg-web-react/OrderFish#/ActivityProgram-edit?search_id=${record.firstHeadPk}&btnPageFlag=${2}`))} >
                {text}
            </a>
        }
    },
    {
        dataIndex: "remark",
        key:"remark",
        title: "备注",
        renderType: "input",
        pattern:/^\S*$/,
        patternMessage: "不能有空格",
        filedProps: {
            maxLenght:200,
        },
        required: false,
    },
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "profitCheckDetails": {
        "title": "明细",
        "type": "grid",
        "column": columnprofitCheckDetails
    },
    "profitCheckAttachments": {
        "title": "附件",
        "type": "grid",
        "column": columnprofitCheckAttachments
    },
}




//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "billcode",
        width: 120,
        key: "billcode",
        fixed: "left",
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'ProfitCheck-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "隶属组织",
        dataIndex: "organizationName",
        width: 150,
        key: "organizationName",
        fixed: "left",
    },
    {
        title: "单据日期",
        dataIndex: "marrkdate",
        key: "marrkdate",
        width: 100,
        render:(text) => {
            return text && ts2Formatter(text);
        },
        fixed: "left",
    },
    {
        title: "审批状态",
        dataIndex: "state",
        key: "state",
        width: 100,
        render:(text, record, index)=> {
            return renderState(text);
        },
        fixed: "left",
    },
    {
        title: "启用状态",
        dataIndex: "isEnable",
        key: "isEnable",
        width: 100,
        render:(text) => {
                return renderEnable(text);
            }
    },
    {
        title:"审核日期",
        dataIndex:"approveTime",
        key: "approveTime",
        width: 100,
        render:(text) => {
            return text && ts2Formatter(text);
        },
        fixed: "left",
    },
    {
        title: "商品品牌",
        dataIndex: "commoditybrandName",
        width: 125,
        key: "commoditybrandName",
    },
    {
        title: "商品品类",
        dataIndex: "goodscategoryName",
        width: 125,
        key: "goodscategoryName",
    },
    {
        title: "部门片区",
        dataIndex: "marketareaName",
        width: 100,
        key: "marketareaName",
    },
    {
        title: "补贴金额",
        dataIndex: "profitamount",
        width: 90,
        key: "profitamount",
        sumCol:true
    },
    {
        title: "制单人",
        dataIndex: "marrkName",
        width: 90,
        key: "marrkName",
    },
    {
        title: "审批管理",
        dataIndex: "approvalName",
        width: 100,
        key: "approvalName",
    },
]

export const searchField = [
    {
        enname: "organization",
        zhname: "隶属组织",
        required: false,
        refname:"organization",
        realRef:true,
        param:{
            "AUTH_refdim": "organization", 
            "AUTH_refcod": "ProfitCheck"
        },
        cascadeName: [{
                paramkey: "EQ_organization.id",
                childtype: "DataHeader",
                refKey: "refpk",
                dtoKey: "organization",
                offers: "marketarea",
                resetOffersFlag: true,
            },
            {
                paramkey: "EQ_customerAreas.organization.id",
                childtype: "DataHeader",
                refKey: "refpk",
                dtoKey: "organization",
                offers: "profitCheckDetails&customer",
                resetOffersFlag: true,
            }
        ],
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "billcode",
        zhname: "单据号",
        required: false,
        type: "FormControl",
        searchType:"like",
        edit: true

    },
    {
        enname: "marrkdate",
        zhname: "单据日期",
        required: false,
        type: "RangePicker",
        rangeField: ["marrkdate", "marrkdate"],
        edit: true
    },
    {
        enname:"approveTime",
        zhname:"审核日期",
        required: false,
        type: "RangePicker",
        rangeField:["approveTime","approveTime"],
        format:"YYYY-MM-DD",
        edit: true
    },
    {
        enname: "marketarea",
        zhname: "部门片区",
        required: false,
        refname:"departmentRef",
        realRef:true,
        alias:"organization",
        param:{
            "AUTH_refdim": "marketarea", 
            "AUTH_refcod": "ProfitCheck"
        },
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "approval",
        zhname: "审批管理",
        required: false,
        realRef:true,
        codeRef:true,
        refname:"approvalDocQRSP001",
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "profitCheckDetails&profitProject",
        zhname: "补贴项目",
        required: false,
        refname:"feeType",
        param:{
            "EQ_subsidyProjectState": "1",
        },
        realRef:true,
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "commoditybrand",
        zhname: "商品品牌",
        required: false,
        realRef:true,
        refname:"brandref",
        param:{
            "AUTH_refdim": "commoditybrand", 
            "AUTH_refcod": "ProfitCheck"
        },
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "goodscategory",
        zhname: "商品品类",
        required: false,
        realRef:true,
        refname:"terminalGoodsCate",
        param:{
            "AUTH_refdim": "goodscategory", 
            "AUTH_refcod": "ProfitCheck"
        },
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "profitCheckDetails&customer",
        zhname: "客户",
        required: false,
        realRef:true,
        alias:"organization",
        param:{
            "AUTH_refdim": "customer", 
            "AUTH_refcod": "ProfitCheck"
        },
        refname:"terminalcustomerRef",
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "profitCheckDetails&custchantype",
        zhname: "客户渠道",
        required: false,
        refname:"custchantype",
        realRef:true,
        param:{
            "AUTH_refdim": "channelType", 
            "AUTH_refcod": "ProfitCheck",
            "EQ_enableState":"2"
        },
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "profitCheckDetails&activityschemebillcode",
        zhname: "决裁单号",
        required: false,
        type: "FormControl",
        searchType:"like",
        edit: true
    },
    {
        enname: "marrk",
        zhname: "创建人",
        required: false,
        refname:"personRef",
        realRef:true,
        param:{
            "AUTH_refdim": "marrk", 
            "AUTH_refcod": "ProfitCheck"
        },
        type: "RefComponent",
        multiple:true,
        edit: true
    },
    {
        enname: "state",
        zhname: "审批状态",
        required: false,
        code:"BILL_STATUS",
        realRef:true,
        type: "Select",
        edit: true
    },
    {
        enname:"isEnable",
        zhname:"启用状态",
        required: false,
        options: [{
            "key": 1,
            "value": "已启用"
        }, {
            "key": 2,
            "value": "停用"
        }],
        type: "Radio",
        edit: true
    },
]

export const headerButtonSets = [
    {
        event: "ButtonEnable",
        zhname: "启用",
        authcode: "Profitstart",
        method: "post",
        batch:true,
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-fee/fee/profit-check/batch-enable'
    },
    {
        event: "ButtonDisable",
        zhname: "停用",
        authcode: "Profitstop",
        method: "post",
        batch:true,
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-fee/fee/profit-check/batch-disable'
    }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-fee/fee/profit-check/deleteOrder'
    },
    "edit": true,
    "detail": true
}

export const SelectCode = ["sale","FA001","BILL_STATUS","FA002","QRSP001"]
